package com.wanjia.bpsapi.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wanjia.bpsapi.mapper.DistanceMapper;
import com.wanjia.bpsapi.pojo.dto.DistanceDto;
import com.wanjia.bpsapi.pojo.entity.Distance;
import com.wanjia.bpsapi.service.IDistanceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class DistanceServiceImpl extends ServiceImpl<DistanceMapper, Distance> implements IDistanceService{
    @Autowired
    DistanceMapper distanceMapper;


    @Override
    public Distance getDistance(Long baseId, Long clientId) {
        QueryWrapper<Distance> wrapper = new QueryWrapper<>();
        wrapper.eq("base_id",baseId);
        wrapper.eq("client_id",clientId);
        Distance data = distanceMapper.selectOne(wrapper);
        return data;
    }

    @Override
    public int updateDis(Distance distance) {
        Long id = distance.getId();
        double distance1 = distance.getDistance();
        int i = distanceMapper.updateDis(id,distance1);
        return i;
    }

    /*@Override
    public List<Distance> getClientIdDis(int uid) {
        QueryWrapper<Distance> wrapper = new QueryWrapper<>();
        wrapper.eq("client_id",uid);
        List<Distance> distanceList = distanceMapper.selectList(wrapper);
        return distanceList;
    }*/

    @Override
    public List<DistanceDto> getlist(Long baseId,Long clientId,Integer pageNo, Integer pageSize) {
        List<DistanceDto> getlist = distanceMapper.getlist(baseId,clientId,pageNo, pageSize);
        return getlist;
    }

    @Override
    public Long countlist(Long baseId, Long clientId) {
        return distanceMapper.countList(baseId, clientId);
    }
}
